I’ve always been opposed to using web-based password generators, you never know if the passwords are logged in with your IP. Most often I have used my own password creation script. Recently, I discovered that you could create a password in with just two lines of code. Just let powershell call a .NET Method().
There is a .Net class called System.Web.Security that we can load via the Assembly “System.Web” and when we look at it´s methods we have a method called GeneratePassword. So we can just call that in powershell to generate a secure password.
The code below shows that we load the Assebly and then we call the method to generate a password with th length of 10 and a minimun of 2 non-alphanumeric characters.
[Reflection.Assembly]::LoadWithPartialName("System.Web") [System.Web.Security.Membership]::GeneratePassword(10,2)
And then we have a random generated password.